package cn.ren.cloud.fallback;

import cn.ren.cloud.enums.GlobelExceptionEnum;
import cn.ren.cloud.feign.CourseFeignClient;
import cn.ren.cloud.result.JsonResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author 23508
 */
@Component
public class CourseFeignClientFallbackFactory implements FallbackFactory<CourseFeignClient> {
    @Override
    public CourseFeignClient create(Throwable throwable) {
        return new CourseFeignClient() {
            /**
             * 通过id获取课程
             *
             * @param id 课程id
             * @return JsonResult.error
             */
            @Override
            public JsonResult get(Long id) {
                return JsonResult.error(GlobelExceptionEnum.COMMON_REPEAT_OPERATION_ERROR.getMessage(), GlobelExceptionEnum.COMMON_REPEAT_OPERATION_ERROR.getCode());
            }

            /**
             * 获取课程详情
             *
             * @param courseIds 课程ids
             * @return 课程
             */
            @Override
            public JsonResult getInfo(String courseIds) {
                return JsonResult.error(GlobelExceptionEnum.COMMON_REPEAT_OPERATION_ERROR.getMessage(), GlobelExceptionEnum.COMMON_REPEAT_OPERATION_ERROR.getCode());
            }
        };
    }
}
